package cn.wolfcode.education.service.impl;

import cn.wolfcode.education.domain.Classroom;
import cn.wolfcode.education.mapper.ClassroomMapper;
import cn.wolfcode.education.query.QueryObject;
import cn.wolfcode.education.service.IClassroomService;
import cn.wolfcode.education.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class ClassroomServiceImpl implements IClassroomService {

    @Autowired
    private ClassroomMapper classroomMapper;
    //新增
    public void insert(Classroom classroom) {
        classroomMapper.insert(classroom);
    }
    //编辑
    public void update(Classroom classroom) {
        classroomMapper.updateByPrimaryKey(classroom);
    }
    //查看教室
    public Classroom queryById(Long id) {
        return classroomMapper.selectByPrimaryKey(id);
    }

    public List<Classroom> queryAll() {
        return classroomMapper.selectAll();
    }

    public PageResult query(QueryObject qo) {
        int total = classroomMapper.queryForCount(qo);
        if(total == 0){
            return new PageResult();
        }
        List<Classroom> rows = classroomMapper.queryForList(qo);
        PageResult pageResult = new PageResult(total,rows);
        return pageResult;
    }
    //保存
    public void save(Classroom role) {
        classroomMapper.insert(role);
    }
    //启用/停用教室
    public void changeStatus(Long id) {
        classroomMapper.changeStatus(id);
    }

    public List<Classroom> queryClassoomByClassgradeId(Long id) {
        return classroomMapper.queryClassoomByClassgradeId(id);
    }
}
